<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>便民药物管理系统</title>
<meta http-equiv="x-ua-compatible" content="IE=10,9,8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<meta charset="UTF-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="自助打印" />
<link rel="apple-touch-icon-precomposed" href="static/images/i/edu.png">

<link rel="stylesheet" href="static/js/LayuiCMS2.0/layui/css/layui.css"
	media="all" />
<link rel="stylesheet" href="static/js/LayuiCMS2.0/css/public.css"
	media="all" />

<script src="static/js/area.js"></script>
<script src="static/js/date.format.js"></script>
<style type="text/css">
.layui-form-item .layui-input-inline {
	width: 215px;
}
</style>
</head>
<body class="childrenBody">
	<form class="layui-form">
		<blockquote class="layui-elem-quote quoteBox">
			<form class="layui-form">
				<div class="layui-form-item">
					 
					 <div class="layui-inline">
						<label class="layui-form-label">省份</label>
						<div class="layui-input-inline">
							<select id="s_province"  lay-filter="s_province" name="s_province">
								<option value="">请选择省份</option>
							</select>
						</div>
					</div> 
					 <div class="layui-inline">
						<label class="layui-form-label">城市</label>
						<div class="layui-input-inline">
							<select id="s_city"  lay-search="">
								<option value="">请选择城市</option>
								
							</select>
						</div>
					</div> 
					
					 <div class="layui-inline">
						<label class="layui-form-label">店名</label>
						<div class="layui-input-inline">
							<input type="text" class="layui-input" id="keyword"
										 placeholder="请输入店名" />
						</div>
					</div> 
					
					<div class="layui-btn-group">
						<button type="button" class="layui-btn search_btn">
							查询&nbsp;<i class="layui-icon">&#xe615;</i>
						</button>
					 	&nbsp;
						&nbsp;
						<button type="button" class="layui-btn layui-icon-add-1 add_btn">新增&nbsp;<i class="layui-icon">&#xe654;</i></button>
						</button>
					</div>
				</div>
			</form>
		</blockquote>
		<table id="newsList" lay-filter="newsList"></table>

		<!--操作-->
		<script type="text/html" id="newsListBar">	
			<a class="layui-btn layui-btn-xs" lay-event="edit">查看</a>
			<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="del">删除</a>
		</script>
	</form>
	<script type="text/javascript"
		src="static/js/LayuiCMS2.0/layui/layui.js"></script>
	<script type="text/javascript">
		layui
				.use(
						[ 'form', 'layer', 'laydate', 'table', 'laytpl' ],
						function() {
							var form = layui.form, layer = parent.layer === undefined ? layui.layer
									: top.layer, $ = layui.jquery, laydate = layui.laydate, laytpl = layui.laytpl, table = layui.table;

							laydate.render({
								elem : '#start',
								type : 'date',
								trigger : "click",
								done : function(value, date, endDate) {
									submitTime = value;
								}
							});

							laydate.render({
								elem : '#end',
								type : 'date',
								trigger : "click",
								done : function(value, date, endDate) {
									submitTime = value;
								}
							});

							//新闻列表
							var tableIns = table
									.render({
										elem : '#newsList',
										url : '${pageContext.request.contextPath }/pharmacy/getPharmacyList',
										cellMinWidth : 95,
										page : true,
										height : "full-185",
										limit : 10,
										limits : [ 10, 15, 20, 25 ],
										id : "newsListTable",
										cols : [ [
												{
													field : 'drug_store',
													title : '店名',
													width : 220,
													align : "center"
												},
												{
													field : 'province',
													title : ' 省',
													width : 120,
													align : "center"
												},
												{
													field : 'city',
													title : '市',
													width : 120,
													align : "center"
												},
												{
													field : 'phone_store',
													title : '门店电话',
													width : 180,
													align : 'center'
												},
												{
													field : 'longitude',
													title : '经度',
													align : "center",
													width : 120
												},
												{
													field : 'latitude',
													title : '纬度',
													align : "center",
													width : 120
												},
												{
													field : 'business_hours',
													title : '营业时间',
													align : "center",
													width : 180
												},
												{
													field : 'address',
													title : '地址',
													align : "center",
							
												},
												/*	{field: 'opApplyNo', title: '手术申请号', align:"center", width:180},*/
												/* {
													field : 'notifyTime',
													title : '支付时间',
													align : 'center',
													templet : function(d) {
														if (d.notifyTime == null) {
															return "";
														}
														return new Date(
																d.notifyTime)
																.format("yyyy-MM-dd hh:mm:ss");
													} 
												}, */ {
													title : '操作',
													width : 120,
													templet : '#newsListBar',
													fixed : "right",
													align : "center"
												} ] ]
									});

							//搜索【此功能需要后台配合，所以暂时没有动态效果演示】
							$(".search_btn").on(
											"click",
											function() {
												var province = $("#s_province").find("option:selected").text();
												var provinceCode = $("#s_province").val();
												var cityCode = $("#s_city").val();
												var city = $("#s_city").find("option:selected").text();
												
												
												if(provinceCode == null || provinceCode==''   || provinceCode == undefined){
													province = null;
												}
												
												if(cityCode == null || cityCode==''   || cityCode == undefined){
													city = null;
												}
												
												
												var keyword = $("#keyword").val();

												if (province || city || keyword ) {

									
													table
															.reload(
																	"newsListTable",
																	{
																		url : '${pageContext.request.contextPath }/pharmacy/getPharmacyList',
																		page : {
																			curr : 1
																		//重新从第 1 页开始
																		},
																		where : {
																			province:province,
																			city:city,
																			keyword : keyword
																		}
																	});
												} else {
													layer.msg("请输入搜索的内容");
												}
											});
							
							
							
							
							
							
							//绑定省份下拉框
							form.on('select(s_province)', function (data) {
							    var index=$("select[name=s_province").val();
							 
							    var arr = dsy.Items["0_"+index];
							    
							    
							    $("#s_city").empty();
							    $("#s_city").append("<option value=''>请选择城市</option>");
							    $.each(arr,function(index,value){
									$("#s_city").append("<option value="+index+">"+value+"</option>"); 
								});
							    form.render('select');
							    
							 });   
							
							//获取省份信息
							function initProvince(){
								var arr = dsy.Items["0"];
								$.each(arr,function(index,value){
										$("#s_province").append("<option  value="+index+">"+value+"</option>"); 
								});
								
								 form.render('select');
								
							}
							
							//初始化省份信息
							initProvince();
							
							
							

							$(".add_btn").click(function(){
								addBasic();
							});
						
						    //添加文章
						    function addBasic(){
						    	var content = "${pageContext.request.contextPath }/pharmacy/pharmacyAddlPage";
						        var index = layui.layer.open({
						            title : "添加信息",
						            type : 2,
						            content : content,
						            success : function(layero, index){
						                var body = layui.layer.getChildFrame('body', index);
						                setTimeout(function(){
						                    layui.layer.tips('点击此处返回列表', '.layui-layer-setwin .layui-layer-close', {
						                        tips: 3
						                    });
						                },500);
						            }
						        });
						        layui.layer.full(index);
						        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
						        $(window).on("resize",function(){
						            layui.layer.full(index);
						        });
						    }

						

							//添加文章
							function updateBasic(edit) {
								var content = "${pageContext.request.contextPath }/pharmacy/pharmacyAddlPage?orderId="
										+ edit.id;
								var index = layui.layer
										.open({
											title : "查看用户",
											type : 2,
											content : content,
											success : function(layero, index) {
												var body = layui.layer
														.getChildFrame('body',
																index);
												setTimeout(
														function() {
															layui.layer
																	.tips(
																			'点击此处返回列表',
																			'.layui-layer-setwin .layui-layer-close',
																			{
																				tips : 3
																			});
														}, 500);
											}
										});
								layui.layer.full(index);
								//改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
								$(window).on("resize", function() {
									layui.layer.full(index);
								});
							}

							function viewBasic(edit) {
								var content = "${pageContext.request.contextPath }/ops/applyOperationUpdate?applyOperationId="
										+ edit.id
										+ "&serialNumberId="
										+ edit.serialNumber + "&view=1";
								var index = layui.layer
										.open({
											title : "添加信息",
											type : 2,
											content : content,
											success : function(layero, index) {
												var body = layui.layer
														.getChildFrame('body',
																index);
												setTimeout(
														function() {
															layui.layer
																	.tips(
																			'点击此处返回列表',
																			'.layui-layer-setwin .layui-layer-close',
																			{
																				tips : 3
																			});
														}, 500);
											}
										});
								layui.layer.full(index);
								//改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
								$(window).on("resize", function() {
									layui.layer.full(index);
								});
							}

							//列表操作
							table
									.on(
											'tool(newsList)',
											function(obj) {
												var layEvent = obj.event, data = obj.data;

												if (layEvent === 'edit') { //编
													updateBasic(data);
												} else if (layEvent === 'view') {
													viewBasic(data);
												} else if (layEvent === 'del') {
													layer
															.confirm(
																	'确认要删除该药店吗?',
																	function(
																			index) {

																		$
																				.ajax({
																					url : '${pageContext.request.contextPath}/pharmacy/delStoreById',
																					type : 'get',
																					data : {
																						'id' : data.id
																					},//向服务端发送删除的id
																					success : function(
																							result) {
																						if (result != null) {
																							var data = $
																									.parseJSON(result);
																							if (data.code == "1") {
																								setTimeout(
																										function() {
																											obj
																													.del(); //删除对应行（tr）的DOM结构，并更新缓存
																											layer
																													.close(index);
																											console
																													.log(index);
																											layer
																													.msg(
																															"删除成功",
																															{
																																icon : 1
																															});
																										},
																										500);
																							} else {
																								layer
																										.msg(
																												"删除失败",
																												{
																													icon : 5
																												});
																								return false;
																							}

																						}
																					}

																				});
																		layer
																				.close(index);
																	});
												}
											});

						});
	</script>
</body>
</html>
